// pages/store/index/index.js
import {
  getStoreClassifyAllApi,
  getStoreAllApi,
  getStoreBannerApi
} from '../../../https/store'
import {
  BASE_URL
} from '../../../constant/index'
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    BASE_URL,
    // 顶部标题栏动态设置
    topBarInfo: {
      navBarHeight: app.globalData.navBarHeight,
      menuRight: app.globalData.menuRight,
      menuTop: app.globalData.menuTop,
      menuHeight: app.globalData.menuHeight,
    },
    classify: [],
    storeList: [],
    banner: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getClassify()
    this.getAllStore()
    this.getBanner()
  },
  // 获取全部的商品
  async getAllStore() {
    const getRes = await getStoreAllApi({
      page: 1,
      limit: 10000
    })
    console.log(getRes)
    if (getRes.code == 200) {
      this.setData({
        storeList: getRes.data.list
      })
    }
  },
  // 获取banner
  async getBanner() {
    const getRes = await getStoreBannerApi();
    console.log(getRes)
    if (getRes.code == 200) {
      const banner = getRes.data.filter(item => item.isShow)
      this.setData({
        banner: banner
      })
    }
  },
  // 获取分类数据
  async getClassify() {
    const getRes = await getStoreClassifyAllApi()
    console.log(getRes)
    if (getRes.code == 200) {
      this.setData({
        classify: getRes.data
      })
    }
  },
  // 跳转分类
  gotoClassify(e) {
    console.log(e)
    const docid = e.currentTarget.dataset.docid
    wx.navigateTo({
      url: '../classify/index?docid=' + docid,
    })
  },
  // 跳转详情页
  gotoDetail(e) {
    console.log(e)
    const docid = e.currentTarget.dataset.docid
    wx.navigateTo({
      url: '../detail/index?docid=' + docid,
    })
  }
})